<extend name="Public:base" />
<block name="content">
<div id="primary" class="inner group">
<div class="layout-sidebar-right group">
   <!-- START CONTENT -->
   <div id="content" role="main" class="group">
      <div id="crumbs" class="theme_breadcumb">
         <a class="home" href="http://yourinspirationweb.com/demo/sommerce">Home Page</a>  &rsaquo;  <a class="no-link current" href="#">My Account</a>
         <div class="breadcrumb-end"></div>
      </div>
      <h2>My Account</h2>
      <div id="post-15" class="post-15 page type-page status-publish hentry group">
         <p>你好, <strong>mauro</strong>. 。从您的帐户中的菜单可以查看您最近的订单，管理您的送货地址和 <a href="/home/login/login/mima">更改您的密码</a>.</p>
         <h2>Recent Orders</h2>
         <table class="shop_table my_account_orders">
            <thead>
               <tr>
                  <th><span class="nobr">商品名称</span></th>
                  <th><span class="nobr">图片</span></th>
                  <th><span class="nobr">单价</span></th>
                  <th><span class="nobr">数量</span></th>
                  <th colspan="2"><span class="nobr">小计</span></th>
               </tr>
            </thead>
            <tbody>
            <foreach name="list" item="order">
            	<tr class="goods" gid={$order.id}>
            		<td>{$order.goods_name}</td>
            		<td><img src="{$order.pic}" height="40"></td>
            		<td class="price">{$order.goods_price}.00</td>
            		<td>{$order.num}</td>
            		<td class="subtotal"></td>
            	</tr>
            </foreach>
            	<tr>
            		<td colspan="4" style="text-align:right;">总计:</td>
            		<td ><span id="total"></span>元</td>
            	</tr>
            </tbody>
         </table>
         <h2>My Addresses</h2>
         <if condition="$addr eq null">
         <p>您还没有地址,请在<a href="/home/goods/address/index">地址管理</a>添加</p>
         <else />
         <p>以下当前拥有的地址,如果想添加或修改,请在<a href="/home/goods/address/index">地址管理</a>中进行添加或修改</p>
         </if>
         <div class="col2-set addresses">
            <table id="my_table" style="width:100%" cellpadding="0" cellspacing="0" class="short-table grey">
               <tbody>
                    <foreach name="addr" item="address">
                        <tr class='dizhi'>
                            <th width="20%" class="features" style="text-align:center; ">{$address.name}</th>
                            <td style="text-align:center; ">{$address.zhuzhi}</td>
                            <td style="text-align:center; ">{$address.zhuzhizhushi}</td>
                            <td style="text-align:center; ">{$address.phone}</td>
                            <td style="text-align:center; ">
                                <a href="" info="moren" aid="{$address.id}" class="read-more">设为默认</a>
                                <img info="moren" status="{$address.status}" aid="{$address.id}" src="__PUBLIC__/home/images/bg/yes.png" alt="" style="display:none">
                            </td>
                        </tr>
                    </foreach>
               </tbody>
            </table>
            <!-- /.col-2 -->
         </div>
         <!-- /.col2-set -->
      </div>
      <div id="comments">
         <!--<p class="nocomments">&nbsp;</p>-->
      </div>
      <!-- #comments -->
   </div>
   <!-- END CONTENT -->
   <!-- START SIDEBAR -->
   <div id="sidebar" class="group">
      <div id="featured-products-3" class="widget-1 widget-first widget widget_featured_products">
         <h3>Must Haves</h3>
         <ul class="product_list_widget">
         	<foreach name="xiang" item="order1">
	            <li>
		            <a href="/home/goods/detail/index/id/{$order1.id}" title="Interior Black">
		            <img width="36" height="36" src="{$order1.zpic}" class="attachment-shop_tiny wp-post-image" alt="interior" title="interior" />
		            <span class="js_widget_product_title">{$order.goods_name}</span>
		            </a>
		            <span class="js_widget_product_price">&#36;{$order.goods_price}.00</span>
	           	</li>
           	</foreach>
         </ul>
      </div>
      <div id="testimonial-widget-3" class="widget-2 widget-last widget testimonial-widget">
         <h3>Testimonials</h3>
         <div class="testimonial-text">
            <ul>
               <li>
                  <blockquote>
                     <p>Quisque vel ipsum nec magna aliquet molestie in quis ipsum. Sed nisl est, hendrerit in laoreet facilisis, placerat eget tortor. Nunc ipsum eros, sagittis quis dignissim sed, imperdiet vitae sem. Praesent et ultricies tellus. Etiam ornare dolor sagittis quis dignissim sed, imperdiet vitae sem. Praesent et ultricies tellus.</p>
                     <a class="name-testimonial" href="http://yourinspirationweb.com/demo/sommerce/bl_testimonials/joy-mergot/">[Joy M�rgot ]</a>
                  </blockquote>
               </li>
               <li>
                  <blockquote>
                     <p>Duis bibendum massa in felis auctor at pellentesque nulla consequat. Duis ornare elementum nisl quis semper. <strong>In consequat tortor</strong> odio, quis iaculis metus. Phasellus neque ipsum, volutpat molestie pellentesque dapibus, dapibus molestie libero</p>
                     <a class="name-testimonial" href="http://yourinspirationweb.com/demo/sommerce/bl_testimonials/elisa-meis/">[Elisa Meis ]</a>
                  </blockquote>
               </li>
               <li>
                  <blockquote>
                     <p>Nunc egestas magna luctus mauris ultricies vitae fermentum lectus faucibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris et augue suscipit est ultricies gravida. Phasellus sollicitudin scelerisque pellentesque. Mauris et augue suscipit!</p>
                     <a class="name-testimonial" href="http://yourinspirationweb.com/demo/sommerce/bl_testimonials/ricardo-mori/">[Ricardo Mori ]</a>
                  </blockquote>
               </li>
            </ul>
            <div class="pagination p-testimonial"></div>
         </div>
         <div class="J_cartBar">
        <div class="section-left">
            <a href="/home/goods/details/all" class="J_goShoping">继续购物</a>
            <span class="cart-total">
                共 
                <i class="J_cartTotalNum">0</i>
                件商品
            </span>
            <span class="total-price" style="padding-left: 400px;">
                    合计（不含运费）：<em class="J_cartTotalPrice">0</em>元
            </span>
            <a href="javascript:;" class="J_goCheckout">结算</a>
        </div>
    </div>
         <script type="text/javascript">
            jQuery(document).ready(function($){
                $('.testimonial-widget ul').cycle({
                    fx:'fade',
                    
                    timeout:8000,
                    speed:300, 
            	    pager:'.p-testimonial'
                });
            });
            order();
            function order(){
            	var total = null;
            	$('.price').each(function(){
            		var price = parseInt($(this).html());
            		var num = parseInt($(this).next().html());
            		var subtotal = price*num;
            		$(this).next().next().html(subtotal);
            		total+=subtotal;
            	});
            	$('#total').html(total);
            	$('.J_cartTotalPrice').html(total);
            }
            $('a.[info="moren"]').click(function(){
                    var id=$(this).attr('aid');
                    var a = $(this);
                    $.ajax({
                        url:'/home/goods/address/status',
                        type:'post',
                        data:{'id':id},
                        success:function(mes){
                            console.log(mes);
                            if(mes=='yes'){
                                $('a.[info="moren"]').css('display','block');
                                $('img[info="moren"]').css('display','none');
                                $('img[info="moren"]').attr('status','0');
                                $(a).css('display','none');
                                $(a).next().css('display','block');
                                $(a).next().attr('status','1');
                                $('.dizhi').css('background','#f6f6f6');
                                $(a).parent().parent().css('background','#fff');
                            }
                        }
                    });
                    return false;
                });

                $('img[status="1"]').css('display','block');
                $('.dizhi').css('background','#f6f6f6');
                $('img[status="1"]').parent().parent().css('background','#fff');
                $('img[status="1"]').prev().css('display','none');
                $('.J_cartTotalNum:eq(0)').html($('.goods').length);
                $('.subtotal').each(function(){
                	$(this).html();
                });
                $('.J_goCheckout').click(function(){
                	var arr = [];
                	$('.goods').each(function(i){
                		arr[i]=$(this).attr('gid');
                	});
                	var aid=$('img[status="1"]').attr('aid');
                	if(!aid){
                		alert('请选择地址之后在提交');
                		return false;
                	}
                	var total=$('.J_cartTotalPrice').html();
                	console.log(arr);
                	$.ajax({
                		url:'/home/goods/order/insert',
                		type:'post',
                		data:{'arr':arr,'aid':aid,'total':total},
                		success:function(mes){
                			// console.log(mes);
                			if(mes=='yes'){
                				alert('结算成功,请在个人中心->查看订单中,查看您的订单');
                				location.href="/home/goods/details/all";
                			}else{
                				alert('结算失败,请刷新后重试');
                			}
                		}
                	});
                	return false;
                });
         </script>
      </div>
   </div>
   <!-- END SIDEBAR -->    
</div>
</div>
</block>